package value_compare.component;

import value_compare.framework.BaseSameTypeCollectionCompare;
import value_compare.framework.CompareOperator;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static java.util.Arrays.asList;
import static value_compare.framework.CompareOperator.*;

/**
 * @author lihao
 * @since 2019-11-04 11:15:07
 */
public class ListCompare<E> extends BaseSameTypeCollectionCompare<List<E>> {

    private static Set<CompareOperator> supported = new HashSet<CompareOperator>(){{
        this.addAll(asList(eq,ne,containsAny,containsAll,notContains));
    }};

    public ListCompare(List<E> left, List<E> right) {
        super(left, right);
    }

    @Override
    protected Set<CompareOperator> supported() {
        return supported;
    }

    @Override
    protected boolean eq() {
        return this.left.size()==this.right.size() && this.left.containsAll(this.right);
    }

    @Override
    protected boolean containsAny() {
        return this.right.stream().anyMatch(this.left::contains);
    }

    @Override
    protected boolean containsAll() {
        return this.left.containsAll(this.right);
    }

    @Override
    protected boolean notContains() {
        return !containsAny();
    }
}
